package com.example.onlineeducation.viewmodel

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.example.onlineeducation.base.BaseViewModel
import com.example.onlineeducation.data.entity.BannerEntity
import com.example.onlineeducation.data.entity.UserProStudyChartEntity
import com.example.onlineeducation.data.entity.UserProStudyTimeEntity
import com.example.onlineeducation.repository.StudyRepository
import com.example.onlineeducation.utils.YcTimeUtils
import com.yc.jetpacklib.net.YcResult
import com.yc.jetpacklib.utils.YcTime
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.onCompletion
import kotlinx.coroutines.flow.zip

class StatisticsStudyTotalAcVM : BaseViewModel() {

    private val mStudyRepository: StudyRepository by lazy { StudyRepository(mApiService) }

    private val _mUserProStudyTime = MutableLiveData<YcResult<UserProStudyTimeEntity>>()
    val mUserProStudyTime: LiveData<YcResult<UserProStudyTimeEntity>> = _mUserProStudyTime

    private val _mUserProStudyChar = MutableLiveData<YcResult<UserProStudyChartEntity>>()
    val mUserProStudyChar: LiveData<YcResult<UserProStudyChartEntity>> = _mUserProStudyChar
    fun initData(proId: String, timeStart: String, timeEnd: String) = ycLaunch {
        showLoading(delayTime = 0)
        mStudyRepository.getUserProStudyTime(proId).zip(mStudyRepository.getUserProStudyChar(proId, timeStart, timeEnd)) { data1, data2 ->
            _mUserProStudyTime.postValue(data1)
            _mUserProStudyChar.postValue(data2)
        }.onCompletion {
            hideLoading()
        }.collect()
    }
}